﻿using System;
using System.Collections.Generic;
using System.Linq;
using FunPokerMakerOnline.Business;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FunPokerMalerOnline.Business.Test
{

    //TODO Commentary end add test case;

    /// <summary>
    /// This class test the Deck class.
    /// </summary>
    [TestClass]
    public class DeckTest
    {
        private List<Card> MyListOfCard;

        /// <summary>
        /// Initialize the data before each test 
        /// </summary>
        [TestInitialize]
        public void Initialize()
        {

            MyListOfCard = new List<Card>();
            for (int i = 1; i < 14; i++)
            {
                Card MyCard = new Card(Kind.Clubs, i);
                MyListOfCard.Add(MyCard);
            }
        }

        /// <summary>
        /// Test the default constructor and check if the number of cars is correct;
        /// </summary>
        [TestMethod]
        public void DeckContructorDefaultCardNumber()
        {

            Deck DeckTest = new Deck(MyListOfCard);

            Assert.AreEqual(13, DeckTest.NumberOfCards);
        }


        [TestMethod]
        public void ShuffleDefault()
        {


            Deck MyTestDeck = new Deck(MyListOfCard);
            MyTestDeck.Shuffle();

        }


        [TestMethod]
        public void ShuffleDefaultNumberOfTime()
        {

            Deck MyTestDeck = new Deck(MyListOfCard);
            MyTestDeck.Shuffle(30);

        }

        [TestMethod]
        public void ShuffleOneToONeNumberOfTime()
        {

            Deck MyTestDeck = new Deck(MyListOfCard);
            MyTestDeck.Shuffle(7, true);

        }

        [TestMethod]
        public void ShuffleOneToONe()
        {

            Deck MyTestDeck = new Deck(MyListOfCard);
            MyTestDeck.Shuffle(true);

        }

        /// <summary>
        /// Test if the method deal return a instance of card.
        /// </summary>
        [TestMethod]
        public void Deal()
        {
            Deck MyTestDeck = new Deck(MyListOfCard);
            Card MyCardDeal = MyTestDeck.Deal();
            Assert.IsNotNull(MyCardDeal);
        }


        /// <summary>
        /// Test if the error is raise when the deck try to deal when is empty
        /// </summary>
        [TestMethod]
        public void DealErrorWhenDeckIsEmpty()
        {
            Deck MyTestDeck = new Deck(MyListOfCard);
            List<Card> MyCardsDealed = new List<Card>();
            try
            {
                for (int i = 0; i < MyTestDeck.NumberOfCards + 1; i++)
                {
                    MyCardsDealed.Add(MyTestDeck.Deal());
                }
            }
            catch (InvalidOperationException ex)
            {
                //TODO flush the harcoded message and Put the real error system
                if (MyCardsDealed.Count() != 13 || ex.Message != "All of the cards were delt")
                {
                    Assert.Fail();
                }
            }
        }

    }
}
